package com.itheima02.Day09;

import java.util.ArrayList;

/**
 * @author 刘全
 * @date 2021/7/25
 */
public class Test3 {
    public static void main(String[] args) {
        //定义方法,参数是两个:1.ArrayList集合,  2.索引
        //获取对应索引位置的元素,并返回
        ArrayList<String> list = new ArrayList<>();
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");
        String s = method(list, 2);
        System.out.println(s.toUpperCase());
    }

    private static <E> E method(ArrayList<E> list, int index) {
        if (list == null) {
            throw new IllegalArgumentException("集合不能为空");
        }
        if (index >list.size()-1||index<0) {
            throw new IndexOutOfBoundsException("索引不在正确范围内");
        }
        return list.get(index);
    }
}
